#!/bin/sh

# must not fail
#set -e 

# debug
#set -x 

echo "Starting $0"

EXTRA_DISTNAME=extra_3_9_1.zip
EXTRA_DIRNAME=extra_3_9_1
EXTRA_SOFTLINK=extra
EXTRA_UNPACKCMD=unzip


### copy to "install"

if [ ! -f ${DISTFILES_INSTALL}/${EXTRA_DISTNAME} ] ; then
    echo "copying ${EXTRA_DISTNAME} to ${DISTFILES_INSTALL}"
    cp ${EXTRA_DISTNAME}     ${DISTFILES_INSTALL}
fi

### unpack if this version dont exist already
if [ -x ${INSTALL_INTO}/${EXTRA_DIRNAME} ] ;then
    echo "${INSTALL_INTO}/${EXTRA_DIRNAME} exists, skipping"
else

    cd ${INSTALL_INTO}
    ${EXTRA_UNPACKCMD} ${DISTFILES_INSTALL}/${EXTRA_DISTNAME} 
    cd -


### soft links
	rm -f ${EXTRA_SOFTLINK}
	ln -s ${EXTRA_DIRNAME} ${INSTALL_INTO}/${EXTRA_SOFTLINK}

### add to environment
	echo "export EXTRA_HOME=${INSTALL_INTO}/${EXTRA_SOFTLINK}" >> ${INSTALL_INTO}/environment
	export EXTRA_HOME=${INSTALL_INTO}/${EXTRA_SOFTLINK}


### chmod
	chown -R  ${JBOSSUS}.${JBOSSGRP} ${INSTALL_INTO}/${EXTRA_DIRNAME}

fi


echo "to setup extra ca service goto ${SMARTCARD20_HOME} and run ./ejbca-extra-ca-service-setup"

echo "End of $0"


